<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *加载model模块
 * @param type $modename
 */
function getModel($modename){
    $info = pathinfo($modename);
    $file = sprintf('%s/%sModel.php',APP_MODEL,$modename);
    if(file_exists($file)){
        include $file;
        $class = $info['basename'].'Model';
        $model = new $class();
        return $model;
    }
    trigger_error($file.'模块不存在');
}

function get($key){
    if(isset($_GET[$key]))
        return $_GET[$key];
    return '';
}
function post($key,$default = null){
    if(isset($_POST[$key]) AND !empty($_POST[$key]))
        return $_POST[$key];
    if($default){
        return $default;
    }
    return '';
}
function isPost(){
    return $_SERVER["REQUEST_METHOD"] == 'POST';
}
/**
 *获取客户端的iP
 * @return type 
 */
function getIP(){
    return $_SERVER['REMOTE_ADDR'];
}
/**
 *页面跳转
 * @param type $url
 */
function go($url){
    header(sprintf('Location: %s',$url));
    die();
}
/**
 *验证邮箱是否合法
 * @param type $str
 * @return type
 */
function isMail($str){
    return preg_match("/^[0-9a-zA-Z]+(?:[\_\-][a-z0-9\-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\.[a-zA-Z]+$/i",$str);
}

?>
